<html>
<script src="/js/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="/js/ckeditor/ckeditor.js" type="text/javascript"></script>
<link href="/js/ckeditor/contents.css" type="text/css" rel="stylesheet">
<script src="/js/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href="/js/bootstrap/css/bootstrap.min.css" type="text/css" rel="stylesheet">
<script src="/js/bootstrap-treeview/dist/bootstrap-treeview.min.js" type="text/javascript"></script>
<link href="/js/bootstrap-treeview/dist/bootstrap-treeview.min.css" type="text/css" rel="stylesheet">
<script src="/js/bootStrap-addTabs/bootstrap.addtabs.min.js" type="text/javascript"></script>
<link href="/js/bootStrap-addTabs/bootstrap.addtabs.css" type="text/css" rel="stylesheet">
<script src="/js/toastr/toastr.min.js" type="text/javascript"></script>
<link href="/js/toastr/toastr.css" type="text/css" rel="stylesheet">
<script src="/js/bootstrap-table/dist/bootstrap-table.min.js" type="text/javascript"></script>
<link href="/js/bootstrap-table/dist/bootstrap-table.min.css" type="text/css" rel="stylesheet">
<script src="/js/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js" type="text/javascript"></script>
<script src="/js/bootstrap-fileinput/js/fileinput.min.js" type="text/javascript"></script>
<link href="/js/bootstrap-fileinput/css/fileinput.min.css" type="text/css" rel="stylesheet">
<script src="/js/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
<script src="/js/bootstrap-dialog/dist/js/bootstrap-dialog.min.js" type="text/javascript"></script>
<link href="/js/bootstrap-dialog/dist/css/bootstrap-dialog.min.css" type="text/css" rel="stylesheet">
<script src="/js/zTreev3/js/jquery.ztree.all.js" type="text/javascript"></script>
<link href="/js/zTreev3/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet">
<style>
    .container-fluid {
        margin-top: 20px;
    }
</style>
<head>
    <title>旅游资管理</title>
</head>
<body>
<div id="toolbar">
    <form class="form-inline" role="form">
        <div class="form-group">
            <input type="text" class="form-control" id="movieName" placeholder="请输入影视名称" name="movieName">
        </div>
        <div class="form-group">
            <select class="form-control" name="years" id="years">
                <option value="">年代:</option>
                <th:block th:each="t : ${tYears}">
                    <option th:value="${t.id}"><span th:text="${t.yName}"></span></option>
                </th:block>
            </select>
            <select class="form-control" name="type" id="type">
                <option value="">类型:</option>
                <th:block th:each="c : ${tType}">
                    <option th:value="${c.id}"><span th:text="${c.tName}"></span></option>
                </th:block>
            </select>
            <select class="form-control" name="area" id="area">
                <option value="">地区:</option>
                <th:block th:each="c : ${tArea}">
                    <option th:value="${c.id}"><span th:text="${c.areaName}"></span></option>
                </th:block>
            </select>
        </div>
        <button type="button" class="btn btn-success" onclick="showbynameandtelephone()">搜索</button>
        <button type="button" class="btn btn-primary" onclick="adds()">添加</button>
        <button type="button" class="btn btn-danger" onclick="deleteall()">批量删除</button>
        <button type="button" class="btn btn-success" onclick="poiout()">导出当前页数据</button>
    </form>
</div>
<table id="table"></table>
<script type="text/javascript">
    // 查询方法
    function showbynameandtelephone() {
        $('#table').bootstrapTable("refresh")
    }

    $('#table').bootstrapTable({
        url: '/TMovie/show',
        toolbar: '#toolbar',
        method: 'post',                      //请求方式（*）
        contentType: "application/x-www-form-urlencoded",
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: true,                   //是否显示分页（*）
        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
        pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
        pageSize: 10,                     //每页的记录行数（*）
        pageList: [5, 10, 15, 20],        //可供选择的每页的行数（*）
        showColumns: true,                  //是否显示所有的列（选择显示的列）
        showRefresh: true,                  //是否显示刷新按钮
        minimumCountColumns: 1,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        height: 600,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
        uniqueId: "id",                     //每一行的唯一标识，一般为主键列
        showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
        //得到查询的参数
        queryParams: function (params) {
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                pageSize: params.limit,                        //页面大小
                pageNum: (params.offset / params.limit) + 1,  //页码
                movieName: $("#movieName").val(),
                years: $("#years").val(),
                type: $("#type").val(),
                area: $("#area").val(),
            };
            return temp;
        },
        columns: [{
            checkbox: true,
            visible: true
        }, {
            field: 'id',
            title: '编号'
        }, {
            field: 'movieName',
            title: '影视名称'
        }, {
            field: 'movieImage',
            title: '影视图片',
            formatter: function (value) {
                var a = "<img src='" + value + "' width='100' height='100'>";
                // var a = "<img src='/file/download?filename=" + value + "'>";
                return a;
            }
        }, {
            field: 'introduction',
            title: '简介'
        }, {
            field: 'actor',
            title: '演员'
        }, {
            field: 'tName',
            title: '类型'
        }, {
            field: 'areaName',
            title: '产地'
        }, {
            field: 'yName',
            title: '上映年'
        }, {
            field: 'score',
            title: '评分'
        }, {
            field: 'updateTime',
            title: '上映时间'
        }, {
            field: 'up',
            title: '上下架',
            formatter: function (value, row, index) {
                if (value == 2) {
                    return "已下架";
                }
                return "已上架"
            }
        }, {
            field: 'examine',
            title: '状态',
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "审核通过";
                }
                if (value == 0) {
                    return "审核失败";
                }
                if (value == 2) {
                    return "等待审核";
                }
            }
        }, {
            field: 'playType',
            title: '播放来源'
        }, {
            field: 'tagName',
            title: '标签',
        }, {
            field: 'cName',
            title: '所属栏位',
        }, {
            field: 'id',
            title: '操作',
            width: 120,
            align: 'center',
            valign: 'middle',
            formatter: function actionFormatter(value, row, index) {
                var id = value;
                var result = "";
                result += "<a href='javascript:updates(" + id + ")' class='btn btn-xs blue' title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
                result += "<a href='javascript:deletebyid(" + id + ")' class='btn btn-xs blue' title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
                result += "<a href='javascript:putaway(" + id + ")' class='btn btn-xs blue' title='上架'><span class='glyphicon glyphicon-ok-circle'></span></a>";
                result += "<a href='javascript:soldout(" + id + ")' class='btn btn-xs blue' title='下架'><span class='glyphicon glyphicon-remove-circle'></span></a>";
                result += "<a href='javascript:tg(" + id + ")' class='btn btn-xs blue' title='通过'><span class='glyphicon glyphicon-thumbs-up'></span></a>";
                result += "<a href='javascript:btg(" + id + ")' class='btn btn-xs blue' title='不通过'><span class='glyphicon glyphicon-thumbs-down'></span></a>";
                return result;
            }
        },]
    });
    $("[name=refresh]").attr("style", "height:34px;");
    $("[name=toggle]").attr("style", "height:34px;");
    $("[data-toggle=dropdown]").attr("style", "height:34px;");

    //实现添加数据的方法
    function adds() {
        BootstrapDialog.show({
            title: '添加',
            message: function (dialog) {
                return $("<div></div>").load("/TMovie/tzadd");
            },
            type: BootstrapDialog.TYPE_PRIMARY,
            size: BootstrapDialog.SIZE_NORMAL,
            closeable: true,
            buttons: [{
                label: '添加',
                cssClass: 'btn btn-primary',
                action: function (dialog) {
                    $.post("/TMovie/add", $("#forms").serialize(), function (pm) {
                        if (pm == 1) {
                            toastr.success("添加成功")
                            dialog.close();
                            $('#table').bootstrapTable("refresh")
                            return
                        }
                        toastr.error("添加失败");
                    }, "text")
                }
            }, {
                label: '关闭',
                action: function (dialog) {
                    dialog.close();
                }
            }]
        });
    }

    //实现更新数据的方法
    function updates(rid) {
        BootstrapDialog.show({
            title: '修改',
            message: function (dialog) {
                return $("<div></div>").load("/TMovie/tzupdate?id=" + rid);
            },
            type: BootstrapDialog.TYPE_PRIMARY,
            size: BootstrapDialog.SIZE_NORMAL,
            closeable: true,
            buttons: [{
                label: '修改',
                cssClass: 'btn btn-primary',
                action: function (dialog) {
                    $.get("/TMovie/update", $("#forms").serialize(), function (pm) {
                        if (pm == 1) {
                            toastr.info("修改成功")
                            dialog.close();
                            $('#table').bootstrapTable("refresh");
                        } else
                            toastr.error("修改失败");
                    }, "text")
                }
            }, {
                label: '关闭',
                action: function (dialog) {
                    dialog.close();
                }
            }]
        });
    }

    //实现批量删除数据的方法
    function deleteall() {
        if (confirm("你确定要删除吗?")) {
            var rids = [];//得到用户选择的数据的ID
            var rows = $("#table").bootstrapTable('getSelections');
            for (var i = 0; i < rows.length; i++) {
                rids.push(rows[i].id);
            }
            alert(rids)
            if (rids == null || rids == "") {
                toastr.error("请先选择");
                return;
            }
            $.ajax({
                url: "/TMovie/deleteall",
                type: "POST",
                data: {rids: rids},
                dataType: "text",
                async: false,
                success: function (pm) {
                    if (pm >= 1) {
                        toastr.error("删除成功")
                        $('#table').bootstrapTable("refresh");
                    }
                }
            })
        }
    }

    //根据id进行删除
    function deletebyid(rid) {
        if (confirm("你确定要删除吗?")) {
            $.get("/TMovie/delete", {id: rid}, function (pm) {
                if (pm == 1) {
                    toastr.error("删除成功");
                    $('#table').bootstrapTable("refresh");
                    return;
                }
                toastr.error("删除失败");
            }, "text")
        }
    }

    //上架
    function putaway(rid) {
        $.get("/TMovie/putaway", {rid: rid}, function (pm) {
            if (pm == 1) {
                toastr.success("上架成功");
                $('#table').bootstrapTable("refresh");
                return;
            }
            toastr.error("上架失败");
        }, "text")
    }

    //下架
    function soldout(rid) {
        $.get("/TMovie/soldout", {rid: rid}, function (pm) {
            if (pm == 1) {
                toastr.error("下架成功");
                $('#table').bootstrapTable("refresh");
                return;
            }
            toastr.error("下架失败");
        }, "text")
    }

    //审核通过
    function tg(rid) {
        $.get("/TMovie/tg", {rid: rid}, function (pm) {
            if (pm == 1) {
                toastr.success("审核通过成功");
                $('#table').bootstrapTable("refresh");
                return;
            }
            toastr.error("审核通过失败");
        }, "text")
    }

    //审核不通过
    function btg(rid) {
        $.get("/TMovie/btg", {rid: rid}, function (pm) {
            if (pm == 1) {
                toastr.error("审核不通过成功");
                $('#table').bootstrapTable("refresh");
                return;
            }
            toastr.error("审核不通过失败");
        }, "text")
    }

    //导出数据
    function poiout() {
        $.get("/TMovie/poiout", function (pm) {
            if (pm == 1) {
                toastr.success("导出成功");
                $('#table').bootstrapTable("refresh");
                return;
            }
            toastr.error("导出失败");
        }, "text")
    }
</script>
</body>
</html>
